<!-- Modal -->
<div class="modal fade" id="newClientModal" tabindex="-1" role="dialog" aria-labelledby="newClientModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h3 class="modal-title" id="newClientModalLabel">Inscription</h3>
      </div>
      <div class="modal-body">
         <p>Inscrivez vous à notre site de voyage pour pouvoir réaliser des achats avantageux!</p>
         <form>
            <div class="form-group">
              <label class="control-label" for="nom">Nom *</label>
              <input type="text" class="form-control required" id="nom" placeholder="Saisir votre nom">
            </div>
            <div class="form-group">
              <label class="control-label" for="prenom">Prénom *</label>
              <input type="text" class="form-control required" id="prenom" placeholder="Saisir votre prénom">
            </div>
            <div class="form-group">
              <label class="control-label" for="adresse">Adresse *</label>
              <input type="text" class="form-control required" id="adresse" placeholder="Saisir votre adresse">
            </div>
            <div class="form-group">
              <label class="control-label" for="mail">Adresse mail *</label>
              <input type="email" class="form-control required" id="mail" name="mail" placeholder="Saisir votre mail">
            </div>
            <div class="form-group">
              <label class="control-label" for="passwordInscription">Mot de passe *</label>
              <input type="password" class="form-control required" id="passwordInscription" name="passwordInscription" placeholder="Mot de passe">
            </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
        <button type="button" id="buttonValiderInscription" class="btn btn-primary">Enregistrer</button>
      </div>
    </div>
  </div>
</div>
<script>
    
    $(document).ready(function(){
        var btn,retourPopup;
        $('#newClientModal').on('show.bs.modal', function (event) {
            btn = $(event.relatedTarget); // Button that triggered the modal
            retourPopup = btn.data('retour-popup');
            checkConnexionForm();
        });
        $(".required").keyup(function () {
           if($(this).attr("id")=="mail"){
            showError( $(this).parent(),$(this).val()=="" || !isValidEmail($(this).val()));                            
           }else{
              showError( $(this).parent(),$(this).val()=="");             
           }
           checkConnexionForm();
        });
        $("#buttonValiderInscription").click(function(){
            $.ajax({
                    type: "POST",
                    url: "<?php echo $BASE_URL; ?>clientController/ajaxInscription",
                    data: { nom: $("#nom").val(), prenom: $("#prenom").val(), adresse: $("#adresse").val(), mail: $("#mail").val(), passwordInscription: $("#passwordInscription").val() },
                    dataType: "json"
                }).done(function( data ) {
                    hide($("#ongletConnexion"));
                    hide($("#ongletInscription"));                        
                    show($("#ongletDeconnexion"));
                    $("#spanUser").html(' '+data.mail);
                    showInfoUser('<?php echo $BASE_URL; ?>');
                    $('#newClientModal').modal('hide');
                    setTimeout(function(){
                            $('#'+retourPopup).modal('show');
                    }, 500);
                });
            });
   });
       
</script>